public class Test3 {

    public static void getElement(int[] array, int index){
        if(array == null){
            throw new NullPointerException("传递的数组为null");
        }

        if(index < 0 || index >= array.length){
            throw new ArrayIndexOutOfBoundsException("传递的数组下标越界");
        }

    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        try {
            System.out.println("before");
            // arr = null;
            System.out.println(arr[100]);
            System.out.println("after");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("after try catch");
    }


    public static void main4(String[] args) {
        int[] array = {1,2,3};
        try {
            System.out.println("before");
            array = null;
            System.out.println(array.length);
            // System.out.println(array[1]);
            System.out.println("after");
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("这是个数组下标越界异常");
            e.printStackTrace();
        }catch (NullPointerException e){
            System.out.println("这是个空指针异常");
            e.printStackTrace();
        }catch (RuntimeException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally 不管怎么样 都是会被执行的!");
        }

        System.out.println("after try catch");
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3};
        try{
            System.out.println("before");
            // array = null;
            // System.out.println(array.length);
            System.out.println(array[100]);
            System.out.println("after");
        }catch (ArrayIndexOutOfBoundsException | NullPointerException e){
            System.out.println("这是个数组下标越界/空指针异常");
            e.printStackTrace();
        }

        System.out.println("after try catch");
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3};
        try{
            System.out.println("before");
            // array = null;
            // System.out.println(array.length);
            System.out.println(array[100]);
            System.out.println("after");
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("这是个数组下标越界异常");
            e.printStackTrace();
        }catch (NullPointerException e){
            System.out.println("这是个空指针异常");
            e.printStackTrace();
        }

        System.out.println("after try catch");
    }

    public static void main1(String[] args) {
        /*int[] array = {1,2};
        getElement(array, 3);*/

        try{
            int[] array = null;
            System.out.println(array.length);

            System.out.println("hahaha...");
        }catch (ArithmeticException e){
            e.printStackTrace();
            System.out.println("空指针异常抛出...");
        }

        System.out.println("程序继续执行...");
    }
}
